const path = require("path");

const aliases = require("./alias");
const resolve = (p) => {
  // resolve("web/entry-runtime-with-compiler.js"), 解析出base为web
  const base = p.split("/")[0];
  if (aliases[base]) {
    // aliases["web"] -> stepbystep-vue2/src/platforms/web
    return path.resolve(aliases[base], p.slice(base.length + 1));
  } else {
    return path.resolve(__dirname, "../", p);
  }
};
// console.log(aliases["web"]);
const builds = {
  "web-full-dev": {
    entry: resolve("web/entry-runtime-with-compiler.js"),
    dest: resolve("dist/vue.js"),
    format: "umd",
  },
  // runtime-only build (Browser)
  "web-runtime-dev": {
    entry: resolve("web/entry-runtime.js"),
    dest: resolve("dist/vue.runtime.js"),
    format: "umd",
  },
};
function genConfig(name) {
  const opts = builds[name];
  const config = {
    input: opts.entry,
    output: {
      file: opts.dest,
      format: opts.format,
      name: opts.moduleName || "Vue",
    },
  };
  return config;
}
exports.getBuild = genConfig;
exports.getAllBuilds = () => Object.keys(builds).map(genConfig);
